﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using LojaVirtual.Comuns.Clientes;
using LojaVirtual.Infra;

namespace LojaWeb.Areas.Admin.Controllers
{
	[Authorize]
    public class ClienteController : Controller
    {
		private UnitOfWork db;

		public ClienteController()
		{
			db = new UnitOfWork();
		}

        // GET: /Admin/Cliente/
        public ViewResult Index()
        {
            return View(db.Clientes.Recuperar().ToList().OrderBy(c => c.Nome));
        }

        // GET: /Admin/Cliente/Details/5
        public ViewResult Details(int id)
        {
			Cliente cliente = db.Clientes.Recuperar(id);
            return View(cliente);
        }

        // GET: /Admin/Cliente/Delete/5
        public ActionResult Delete(int id)
        {
            Cliente cliente = db.Clientes.Recuperar(id);
            return View(cliente);
        }

        //
        // POST: /Admin/Cliente/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {            
            Cliente cliente = db.Clientes.Recuperar(id);
            db.Clientes.Delete(cliente);
            db.SalvarAlteracoes();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}